/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainMenuFrame.java
 *
 * Created on 29/08/2011, 09:40:17 AM
 */
package Gui;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import Utilities.*;

/**
 *
 * @author pchang
 */
public class MainMenuFrame extends javax.swing.JFrame {

    /** Creates new form MainMenuFrame */
    public MainMenuFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainTabbedPane = new javax.swing.JTabbedPane();
        portTab = new javax.swing.JPanel();
        portTabPanel = new javax.swing.JTabbedPane();
        createPortTab = new javax.swing.JPanel();
        portNameTextField = new javax.swing.JTextField();
        portNameLabel = new javax.swing.JLabel();
        portCountryTextField = new javax.swing.JTextField();
        portCountryLabel = new javax.swing.JLabel();
        portCoordTextField = new javax.swing.JTextField();
        portCoordLabel = new javax.swing.JLabel();
        createPortButton = new javax.swing.JButton();
        displayPortTab = new javax.swing.JPanel();
        manageCargo = new javax.swing.JPanel();
        shipTab = new javax.swing.JPanel();
        shipTabPanel = new javax.swing.JTabbedPane();
        createShipTab = new javax.swing.JPanel();
        displayShipTab = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        portTabPanel.setTabPlacement(javax.swing.JTabbedPane.LEFT);

        portNameLabel.setText("Nombre:");

        portCountryLabel.setText("Pais:");

        portCoordLabel.setText("Coordenada:");

        createPortButton.setText("Crear Puerto");
        createPortButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createPortButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout createPortTabLayout = new javax.swing.GroupLayout(createPortTab);
        createPortTab.setLayout(createPortTabLayout);
        createPortTabLayout.setHorizontalGroup(
            createPortTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(createPortTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(createPortTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(createPortTabLayout.createSequentialGroup()
                        .addComponent(portNameLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(portNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 310, Short.MAX_VALUE))
                    .addGroup(createPortTabLayout.createSequentialGroup()
                        .addComponent(portCountryLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(portCountryTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE))
                    .addGroup(createPortTabLayout.createSequentialGroup()
                        .addComponent(portCoordLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(portCoordTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 284, Short.MAX_VALUE))
                    .addComponent(createPortButton, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        createPortTabLayout.setVerticalGroup(
            createPortTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(createPortTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(createPortTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(portNameLabel)
                    .addComponent(portNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(createPortTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(portCountryLabel)
                    .addComponent(portCountryTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(createPortTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(portCoordLabel)
                    .addComponent(portCoordTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(createPortButton)
                .addContainerGap(151, Short.MAX_VALUE))
        );

        portTabPanel.addTab("Crear Puerto", createPortTab);

        javax.swing.GroupLayout displayPortTabLayout = new javax.swing.GroupLayout(displayPortTab);
        displayPortTab.setLayout(displayPortTabLayout);
        displayPortTabLayout.setHorizontalGroup(
            displayPortTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 402, Short.MAX_VALUE)
        );
        displayPortTabLayout.setVerticalGroup(
            displayPortTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 327, Short.MAX_VALUE)
        );

        portTabPanel.addTab("Adm. Puerto", displayPortTab);

        javax.swing.GroupLayout manageCargoLayout = new javax.swing.GroupLayout(manageCargo);
        manageCargo.setLayout(manageCargoLayout);
        manageCargoLayout.setHorizontalGroup(
            manageCargoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 402, Short.MAX_VALUE)
        );
        manageCargoLayout.setVerticalGroup(
            manageCargoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 327, Short.MAX_VALUE)
        );

        portTabPanel.addTab("Adm. Carga", manageCargo);

        javax.swing.GroupLayout portTabLayout = new javax.swing.GroupLayout(portTab);
        portTab.setLayout(portTabLayout);
        portTabLayout.setHorizontalGroup(
            portTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(portTabPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE)
        );
        portTabLayout.setVerticalGroup(
            portTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(portTabPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 335, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        mainTabbedPane.addTab("Puertos", portTab);

        shipTabPanel.setTabPlacement(javax.swing.JTabbedPane.LEFT);

        javax.swing.GroupLayout createShipTabLayout = new javax.swing.GroupLayout(createShipTab);
        createShipTab.setLayout(createShipTabLayout);
        createShipTabLayout.setHorizontalGroup(
            createShipTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 407, Short.MAX_VALUE)
        );
        createShipTabLayout.setVerticalGroup(
            createShipTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 318, Short.MAX_VALUE)
        );

        shipTabPanel.addTab("Crear Barco", createShipTab);

        javax.swing.GroupLayout displayShipTabLayout = new javax.swing.GroupLayout(displayShipTab);
        displayShipTab.setLayout(displayShipTabLayout);
        displayShipTabLayout.setHorizontalGroup(
            displayShipTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 407, Short.MAX_VALUE)
        );
        displayShipTabLayout.setVerticalGroup(
            displayShipTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 318, Short.MAX_VALUE)
        );

        shipTabPanel.addTab("Adm. Barco", displayShipTab);

        javax.swing.GroupLayout shipTabLayout = new javax.swing.GroupLayout(shipTab);
        shipTab.setLayout(shipTabLayout);
        shipTabLayout.setHorizontalGroup(
            shipTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(shipTabPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE)
        );
        shipTabLayout.setVerticalGroup(
            shipTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(shipTabPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 326, Short.MAX_VALUE)
        );

        mainTabbedPane.addTab("Barcos", shipTab);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 509, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainTabbedPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void createPortButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createPortButtonActionPerformed
        
       principal.crearPuerto(portNameTextField.getText(), portCountryTextField.getText(),portCoordLabel.getText());
        // TODO add your handling code here:
    }//GEN-LAST:event_createPortButtonActionPerformed
    public Principal principal = new Principal();

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        String s = "";
        float cargaMaxima = 100;
        JFrame frame = new JFrame();
        boolean ingresoInvalido = true;
        while (ingresoInvalido) {
            try {
                 s = (String) JOptionPane.showInputDialog(
                null, "Por favor ingrese la carga máxima",
                "Ingreso Carga Máxima",
                JOptionPane.PLAIN_MESSAGE,
                null,
                null,
                "100");
                cargaMaxima = Float.parseFloat(s);
                ingresoInvalido = false;
            } catch (NumberFormatException nf) {
                JOptionPane.showMessageDialog(frame, "No ingresó un número válido");
                ingresoInvalido = true;
            }
        }
        if ((s != null) && (s.length() > 0)) {
            Contenedor.setCapacidad(cargaMaxima);
        } else {
            JOptionPane.showConfirmDialog(null, "Come on, finish the sentence!");
        }
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainMenuFrame().setVisible(true);
            }
        });

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton createPortButton;
    private javax.swing.JPanel createPortTab;
    private javax.swing.JPanel createShipTab;
    private javax.swing.JPanel displayPortTab;
    private javax.swing.JPanel displayShipTab;
    private javax.swing.JTabbedPane mainTabbedPane;
    private javax.swing.JPanel manageCargo;
    private javax.swing.JLabel portCoordLabel;
    private javax.swing.JTextField portCoordTextField;
    private javax.swing.JLabel portCountryLabel;
    private javax.swing.JTextField portCountryTextField;
    private javax.swing.JLabel portNameLabel;
    private javax.swing.JTextField portNameTextField;
    private javax.swing.JPanel portTab;
    private javax.swing.JTabbedPane portTabPanel;
    private javax.swing.JPanel shipTab;
    private javax.swing.JTabbedPane shipTabPanel;
    // End of variables declaration//GEN-END:variables
}
